/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets.customer;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import services.ServiceCart;

/**
 *
 * @author khalifaabdelaziz
 */
public class ServletCartInfo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       ServiceCart serviceCart = new ServiceCart();
        HttpSession session = request.getSession();
        String uid=(String) session.getAttribute("userId");
        if(uid!=null){
       int userId = Integer.parseInt((String) uid);
       response.getWriter().print(serviceCart.countProductsInCart(userId));
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
         ServiceCart serviceCart = new ServiceCart();
        HttpSession session = request.getSession();
        String uid=(String) session.getAttribute("userId");
        if(uid!=null){
       int userId = Integer.parseInt((String) uid);
     
       response.getWriter().print(serviceCart.totalCartPrice(userId));
        }
    }

}
